/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.persistence.proxy;

import apus.entity.AbstractEntity;
import apus.persistence.AbstractDAO;
import apus.services.ServiceLocator;

/**
 * @author Maxim Vasilevsky
 * @author Roman Dyatkovsky
 * @since APUS v0.5
 */
public abstract class AbstractProxy <TypeEn extends AbstractEntity,TypeDAO extends AbstractDAO<TypeEn>> {
    
    protected int id;
    protected TypeEn proxyObject;
    private Class<TypeDAO> clazz;

    public AbstractProxy(Class<TypeDAO> clazz) {
        this.clazz = clazz;
    }
    
    public TypeEn getProxy () {
        if (proxyObject==null){
            proxyObject = ServiceLocator.getService(clazz).read(id);
        }
        return proxyObject;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
        if (proxyObject != null) {
            proxyObject.setId(id);
        }
    }
      
}